import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;

/**
 * Form for receiving from user name, and value of the new setting.
 */
public class ApplicationSettingForm extends Form {
	// Test field for entering From field
	private TextField fromField;
	// Text field for entering Clickatell API ID
	private TextField apiIdField;
	// Text field for entering Clickatell username
	private TextField usernameField;
	// Text field for entering Clickatell password
	private TextField passwordField;

	// Command for saving new setting in record store.
	private Command cmdSave;
	// Command for altering saving new setting.
	private Command cmdBack;

	/**
	 * Constructor.
	 */
	public ApplicationSettingForm() {
		super("Application Settings");
		fromField = new TextField("From", null, 30, TextField.PHONENUMBER);
		append(fromField);
		apiIdField = new TextField("API ID", null, 30, TextField.NUMERIC);
		append(apiIdField);
		usernameField = new TextField("Username", null, 30, TextField.ANY);
		append(usernameField);
		passwordField = new TextField("Password", null, 30, TextField.PASSWORD);
		append(passwordField);

		cmdSave = new Command("Save", Command.SCREEN, 0);
		addCommand(cmdSave);
		cmdBack = new Command("Back", Command.BACK, 0);
		addCommand(cmdBack);
	}

	/**
	 * Clears entered values in text fields of form.
	 */
	public void clear() {
		fromField.setString(null);
		apiIdField.setString(null);
		usernameField.setString(null);
		passwordField.setString(null);
	}
	
	public void setFields(String from, String apiId, String username, String password) {
		fromField.setString(from);
		apiIdField.setString(apiId);
		usernameField.setString(username);
		passwordField.setString(password);
	}

	/**
	 * Gets from name text field name of new setting and returns it.
	 * 
	 * @return name of new setting.
	 */
	public String getFrom() {
		return fromField.getString();
	}
	
	/**
	 * Gets from name text field name of new setting and returns it.
	 * 
	 * @return name of new setting.
	 */
	public String getAPIId() {
		return apiIdField.getString();
	}

	/**
	 * Gets from value text field value of new setting and returns it.
	 * 
	 * @return value of new setting.
	 */
	public String getUsername() {
		return usernameField.getString();
	}
	
	/**
	 * Gets from value text field value of new setting and returns it.
	 * 
	 * @return value of new setting.
	 */
	public String getPassword() {
		return passwordField.getString();
	}

	/**
	 * @return command for saving new setting in record store.
	 */
	public Command getSaveCommand() {
		return cmdSave;
	}

	/**
	 * @return command for altering saving new setting.
	 */
	public Command getBackCommand() {
		return cmdBack;
	}
}